package com.lc.rongzecaifu.adapter;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lc.rongzecaifu.conn.JsonIndex;
import com.lc.rongzecaifu.progress.SaundProgressBar;
import com.lc.rongzecaifu.rongzecaifu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/12.
 */
public class IconListAdapter extends BaseAdapter {

    private Context context;
    private List<JsonIndex.Info.Borrow_list> menuListContent = new ArrayList<>();

    public IconListAdapter(Context context, List<JsonIndex.Info.Borrow_list> menuListContent) {
        this.context = context;
        this.menuListContent = menuListContent;
    }

    @Override
    public int getCount() {
        return menuListContent.size();
    }

    @Override
    public Object getItem(int position) {
        return menuListContent.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = LayoutInflater.from(context).inflate(R.layout.item_home_list, null);

//            MyApplication.scaleScreenHelper.loadView((ViewGroup) convertView);

            viewHolder = new ViewHolder();

            viewHolder.tv_home_list_title = (TextView) convertView.findViewById(R.id.tv_home_list_title);

            viewHolder.tv_home_list_desc = (TextView) convertView.findViewById(R.id.tv_home_list_desc);


            viewHolder.tv_sumMoney = (TextView) convertView.findViewById(R.id.tv_sumMoney);
            viewHolder.mPbar = (SaundProgressBar) convertView.findViewById(R.id.regularprogressbar);
            viewHolder.mPbar.setMax(100);
            Drawable indicator = context.getResources().getDrawable(
                    R.mipmap.jindu4);
            Rect bounds = new Rect(0, 0, indicator.getIntrinsicWidth(),
                    indicator.getIntrinsicHeight());
            indicator.setBounds(bounds);

            viewHolder.mPbar.setProgressIndicator(indicator);
            viewHolder.mPbar.setmText(menuListContent.get(position).progress);
            viewHolder.mPbar.setVisibility(View.VISIBLE);
            String str_progress=menuListContent.get(position).progress;

            Double d=Double.valueOf(str_progress);


            viewHolder.mPbar.setProgress(d.intValue());


            viewHolder.tv_name= (TextView) convertView.findViewById(R.id.tv_name);



            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        //年华利率
        viewHolder.tv_home_list_title.setText("预计年化收益率"+menuListContent.get(position).borrow_interest_rate+"%");

        //期限
        viewHolder.tv_home_list_desc.setText("期限"+menuListContent.get(position).borrow_duration+menuListContent.get(position).borrow_duration_cn);
        //首页项目名称
        viewHolder.tv_name.setText(menuListContent.get(position).borrow_name);
        viewHolder.tv_sumMoney.setText(menuListContent.get(position).need);



        return convertView;

    }

    private class ViewHolder {

        public TextView tv_home_list_title, tv_home_list_desc;

        public SaundProgressBar mPbar;


        public TextView tv_sumMoney;

        //首页标题
        public TextView tv_name;




    }

}
